<template>
  <div class="container">
      <el-form ref="form" :model="form" label-width="120px" style="width:80%">
        <!-- <el-form-item label="基础信息" style="font-bold:600"></el-form-item> -->
        <div style="font-bold:600;line-height:75px;margin-left:50px">基础信息</div>
        <el-form-item label="机构负责人："> 
          <el-input :value="this.masterData.master" id="master" style="width:35%"></el-input>
        </el-form-item>
        <el-form-item label="手机号："> 
          <span>{{this.masterData.phone}}(如需更改请联系400-661-0768)</span>
        </el-form-item>
        <el-form-item label="机构地址："> 
          <el-input :value="this.masterData.address" id="address" style="width:35%"></el-input>
        </el-form-item>
        <div style="font-bold:600;line-height:75px;margin-left:50px">机构信息</div>
        <el-form-item label="机构名称："> 
          <el-input :value="this.masterData.name" id="name" style="width:35%"></el-input>
        </el-form-item>
        <el-form-item label="机构Logo："> 
          <el-input :value="this.masterData.logo" id="logo" style="width:35%"></el-input>
        </el-form-item>
        <el-form-item label="机构介绍">
          <el-input type="textarea" id="introduction" :value="this.masterData.introduction" style="width:50%"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">保存</el-button>
        </el-form-item>
      </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      masterData:"",
      form: {
          master: "",
          address: "", //机构地址
          organizationname: "", //机构名称
          organizationLogo: "", //机构Logo
          organizationintroduce: "" //机构介绍
        } 
      };  
    },
  created() {
    this.getData();
  },
  computed: {
    data() {
      return this.masterData.filter(d => {
        return d;
      });
    }
  },
  methods: {
    //获取机构信息
    getData() {
      var that = this;
      let organizationId = JSON.parse(localStorage.getItem("organizationIds"))[0];
      this.url = '/api/user/xzs/organization.info.get';
      this.$axios({
        url:this.url,
        method:"post",
        data:{
          organizationId:organizationId,
        },
        transformRequest: [
          function(data) {
            let ret = "";
            for (let it in data) {
              ret += encodeURIComponent(it) + "=" + encodeURIComponent(data[it]) + "&";
            }
            return ret;
          }
        ],
      }).then( res =>{  
        this.masterData = res.data.data;
      }).catch(err =>{
        console.log(err);
      })
    },
    // 保存机构基础信息
    onSubmit() {
      var master = document. getElementById("master");
      var address = document. getElementById("address");
      var name = document. getElementById("name");
      var logo = document. getElementById("logo");
      var introduction = document. getElementById("introduction");
      var that = this;
      this.url = "/api/user/xzs/organization.info.update";
      let organizationId = JSON.parse(localStorage.getItem("organizationIds"))[0];
      this.$axios({
        url: this.url,
        method: "post",
        data:{
          master: master.value,
          address: address.value,
          name: name.value,
          logo: logo.value,
          introduction: introduction.value,
          organizationId: organizationId
        },
        transformRequest: [
          function(data) {
            let ret = "";
            for (let it in data) {
              ret += encodeURIComponent(it) + "=" + encodeURIComponent(data[it]) + "&";
            }
            return ret;
          }
        ]
      }).then(res => {
          if(res.data.errorCode == 0){
            this.$message({
              showClose: true,
              message: "保存成功",
              type: "success"
            });
          }
        }).catch(err => {
          console.log(err);
        });
    }
  }
};
</script>
<style>

</style>
